.class public Lcom/mime/qweibo/QAsyncHttpClient;
.super Ljava/lang/Object;
.source "QAsyncHttpClient.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;
    }
.end annotation


# static fields
.field private static final CONNECTION_TIMEOUT:I = 0x4e20


# instance fields
.field private mThreadPool:Ljava/util/concurrent/ExecutorService;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 30
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 138
    const/16 v0, 0x14

    invoke-static {v0}, Ljava/util/concurrent/Executors;->newFixedThreadPool(I)Ljava/util/concurrent/ExecutorService;

    move-result-object v0

    iput-object v0, p0, Lcom/mime/qweibo/QAsyncHttpClient;->mThreadPool:Ljava/util/concurrent/ExecutorService;

    .line 30
    return-void
.end method


# virtual methods
.method public httpGet(Ljava/lang/String;Ljava/lang/String;Lcom/mime/qweibo/QAsyncHandler;Ljava/lang/Object;)Z
    .locals 5
    .parameter "url"
    .parameter "queryString"
    .parameter "callback"
    .parameter "cookie"

    .prologue
    .line 49
    if-eqz p1, :cond_0

    const-string v1, ""

    invoke-virtual {p1, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_1

    .line 50
    :cond_0
    const/4 v1, 0x0

    .line 59
    :goto_0
    return v1

    .line 52
    :cond_1
    if-eqz p2, :cond_2

    const-string v1, ""

    invoke-virtual {p2, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-nez v1, :cond_2

    .line 53
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-static {p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v2, "?"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    .line 55
    :cond_2
    new-instance v0, Lorg/apache/commons/httpclient/methods/GetMethod;

    invoke-direct {v0, p1}, Lorg/apache/commons/httpclient/methods/GetMethod;-><init>(Ljava/lang/String;)V

    .line 56
    .local v0, httpGet:Lorg/apache/commons/httpclient/methods/GetMethod;
    invoke-virtual {v0}, Lorg/apache/commons/httpclient/methods/GetMethod;->getParams()Lorg/apache/commons/httpclient/params/HttpMethodParams;

    move-result-object v1

    const-string v2, "http.socket.timeout"

    .line 57
    new-instance v3, Ljava/lang/Integer;

    const/16 v4, 0x4e20

    invoke-direct {v3, v4}, Ljava/lang/Integer;-><init>(I)V

    .line 56
    invoke-virtual {v1, v2, v3}, Lorg/apache/commons/httpclient/params/HttpMethodParams;->setParameter(Ljava/lang/String;Ljava/lang/Object;)V

    .line 58
    iget-object v1, p0, Lcom/mime/qweibo/QAsyncHttpClient;->mThreadPool:Ljava/util/concurrent/ExecutorService;

    new-instance v2, Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;

    invoke-direct {v2, p0, v0, p3, p4}, Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;-><init>(Lcom/mime/qweibo/QAsyncHttpClient;Lorg/apache/commons/httpclient/HttpMethod;Lcom/mime/qweibo/QAsyncHandler;Ljava/lang/Object;)V

    invoke-interface {v1, v2}, Ljava/util/concurrent/ExecutorService;->submit(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;

    .line 59
    const/4 v1, 0x1

    goto :goto_0
.end method

.method public httpPost(Ljava/lang/String;Ljava/lang/String;Lcom/mime/qweibo/QAsyncHandler;Ljava/lang/Object;)Z
    .locals 5
    .parameter "url"
    .parameter "queryString"
    .parameter "callback"
    .parameter "cookie"

    .prologue
    .line 77
    if-eqz p1, :cond_0

    const-string v1, ""

    invoke-virtual {p1, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_1

    .line 78
    :cond_0
    const/4 v1, 0x0

    .line 90
    :goto_0
    return v1

    .line 80
    :cond_1
    new-instance v0, Lorg/apache/commons/httpclient/methods/PostMethod;

    invoke-direct {v0, p1}, Lorg/apache/commons/httpclient/methods/PostMethod;-><init>(Ljava/lang/String;)V

    .line 81
    .local v0, httpPost:Lorg/apache/commons/httpclient/methods/PostMethod;
    const-string v1, "Content-Type"

    .line 82
    const-string v2, "application/x-www-form-urlencoded"

    .line 81
    invoke-virtual {v0, v1, v2}, Lorg/apache/commons/httpclient/methods/PostMethod;->addParameter(Ljava/lang/String;Ljava/lang/String;)V

    .line 83
    invoke-virtual {v0}, Lorg/apache/commons/httpclient/methods/PostMethod;->getParams()Lorg/apache/commons/httpclient/params/HttpMethodParams;

    move-result-object v1

    const-string v2, "http.socket.timeout"

    .line 84
    new-instance v3, Ljava/lang/Integer;

    const/16 v4, 0x4e20

    invoke-direct {v3, v4}, Ljava/lang/Integer;-><init>(I)V

    .line 83
    invoke-virtual {v1, v2, v3}, Lorg/apache/commons/httpclient/params/HttpMethodParams;->setParameter(Ljava/lang/String;Ljava/lang/Object;)V

    .line 85
    if-eqz p2, :cond_2

    const-string v1, ""

    invoke-virtual {p2, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-nez v1, :cond_2

    .line 86
    new-instance v1, Lorg/apache/commons/httpclient/methods/ByteArrayRequestEntity;

    .line 87
    invoke-virtual {p2}, Ljava/lang/String;->getBytes()[B

    move-result-object v2

    invoke-direct {v1, v2}, Lorg/apache/commons/httpclient/methods/ByteArrayRequestEntity;-><init>([B)V

    .line 86
    invoke-virtual {v0, v1}, Lorg/apache/commons/httpclient/methods/PostMethod;->setRequestEntity(Lorg/apache/commons/httpclient/methods/RequestEntity;)V

    .line 89
    :cond_2
    iget-object v1, p0, Lcom/mime/qweibo/QAsyncHttpClient;->mThreadPool:Ljava/util/concurrent/ExecutorService;

    new-instance v2, Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;

    invoke-direct {v2, p0, v0, p3, p4}, Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;-><init>(Lcom/mime/qweibo/QAsyncHttpClient;Lorg/apache/commons/httpclient/HttpMethod;Lcom/mime/qweibo/QAsyncHandler;Ljava/lang/Object;)V

    invoke-interface {v1, v2}, Ljava/util/concurrent/ExecutorService;->submit(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;

    .line 90
    const/4 v1, 0x1

    goto :goto_0
.end method

.method public httpPostWithFile(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lcom/mime/qweibo/QAsyncHandler;Ljava/lang/Object;)Z
    .locals 18
    .parameter "url"
    .parameter "queryString"
    .parameter
    .parameter "callback"
    .parameter "cookie"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            "Ljava/util/List",
            "<",
            "Lcom/mime/qweibo/QParameter;",
            ">;",
            "Lcom/mime/qweibo/QAsyncHandler;",
            "Ljava/lang/Object;",
            ")Z"
        }
    .end annotation

    .prologue
    .line 108
    .local p3, files:Ljava/util/List;,"Ljava/util/List<Lcom/mime/qweibo/QParameter;>;"
    if-eqz p1, :cond_0

    const-string v3, ""

    move-object/from16 v0, p1

    invoke-virtual {v0, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-eqz v3, :cond_1

    .line 109
    :cond_0
    const/4 v3, 0x0

    .line 135
    :goto_0
    return v3

    .line 111
    :cond_1
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-static/range {p1 .. p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const/16 v4, 0x3f

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    move-result-object v3

    move-object/from16 v0, p2

    invoke-virtual {v3, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    .line 112
    new-instance v10, Lorg/apache/commons/httpclient/methods/PostMethod;

    move-object/from16 v0, p1

    invoke-direct {v10, v0}, Lorg/apache/commons/httpclient/methods/PostMethod;-><init>(Ljava/lang/String;)V

    .line 113
    .local v10, httpPost:Lorg/apache/commons/httpclient/methods/PostMethod;
    invoke-static/range {p2 .. p2}, Lcom/mime/qweibo/utils/QHttpUtil;->getQueryParameters(Ljava/lang/String;)Ljava/util/List;

    move-result-object v14

    .line 114
    .local v14, listParams:Ljava/util/List;,"Ljava/util/List<Lcom/mime/qweibo/QParameter;>;"
    invoke-interface {v14}, Ljava/util/List;->size()I

    move-result v4

    if-nez p3, :cond_2

    const/4 v3, 0x0

    :goto_1
    add-int v13, v4, v3

    .line 115
    .local v13, length:I
    new-array v0, v13, [Lorg/apache/commons/httpclient/methods/multipart/Part;

    move-object/from16 v16, v0

    .line 116
    .local v16, parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    const/4 v11, 0x0

    .line 117
    .local v11, i:I
    invoke-interface {v14}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v3

    :goto_2
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-nez v4, :cond_3

    .line 122
    :try_start_0
    invoke-interface/range {p3 .. p3}, Ljava/util/List;->iterator()Ljava/util/Iterator;
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v17

    move v12, v11

    .end local v11           #i:I
    .local v12, i:I
    :goto_3
    :try_start_1
    invoke-interface/range {v17 .. v17}, Ljava/util/Iterator;->hasNext()Z
    :try_end_1
    .catch Ljava/io/FileNotFoundException; {:try_start_1 .. :try_end_1} :catch_1

    move-result v3

    if-nez v3, :cond_4

    .line 132
    new-instance v3, Lorg/apache/commons/httpclient/methods/multipart/MultipartRequestEntity;

    .line 133
    invoke-virtual {v10}, Lorg/apache/commons/httpclient/methods/PostMethod;->getParams()Lorg/apache/commons/httpclient/params/HttpMethodParams;

    move-result-object v4

    move-object/from16 v0, v16

    invoke-direct {v3, v0, v4}, Lorg/apache/commons/httpclient/methods/multipart/MultipartRequestEntity;-><init>([Lorg/apache/commons/httpclient/methods/multipart/Part;Lorg/apache/commons/httpclient/params/HttpMethodParams;)V

    .line 132
    invoke-virtual {v10, v3}, Lorg/apache/commons/httpclient/methods/PostMethod;->setRequestEntity(Lorg/apache/commons/httpclient/methods/RequestEntity;)V

    .line 134
    move-object/from16 v0, p0

    iget-object v3, v0, Lcom/mime/qweibo/QAsyncHttpClient;->mThreadPool:Ljava/util/concurrent/ExecutorService;

    new-instance v4, Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;

    move-object/from16 v0, p0

    move-object/from16 v1, p4

    move-object/from16 v2, p5

    invoke-direct {v4, v0, v10, v1, v2}, Lcom/mime/qweibo/QAsyncHttpClient$AsyncThread;-><init>(Lcom/mime/qweibo/QAsyncHttpClient;Lorg/apache/commons/httpclient/HttpMethod;Lcom/mime/qweibo/QAsyncHandler;Ljava/lang/Object;)V

    invoke-interface {v3, v4}, Ljava/util/concurrent/ExecutorService;->submit(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;

    .line 135
    const/4 v3, 0x1

    goto :goto_0

    .line 114
    .end local v12           #i:I
    .end local v13           #length:I
    .end local v16           #parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    :cond_2
    invoke-interface/range {p3 .. p3}, Ljava/util/List;->size()I

    move-result v3

    goto :goto_1

    .line 117
    .restart local v11       #i:I
    .restart local v13       #length:I
    .restart local v16       #parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    :cond_3
    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v15

    check-cast v15, Lcom/mime/qweibo/QParameter;

    .line 118
    .local v15, param:Lcom/mime/qweibo/QParameter;
    add-int/lit8 v12, v11, 0x1

    .end local v11           #i:I
    .restart local v12       #i:I
    new-instance v4, Lorg/apache/commons/httpclient/methods/multipart/StringPart;

    iget-object v5, v15, Lcom/mime/qweibo/QParameter;->mName:Ljava/lang/String;

    .line 119
    iget-object v7, v15, Lcom/mime/qweibo/QParameter;->mValue:Ljava/lang/String;

    invoke-static {v7}, Lcom/mime/qweibo/utils/QHttpUtil;->formParamDecode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v7

    const-string v8, "UTF-8"

    invoke-direct {v4, v5, v7, v8}, Lorg/apache/commons/httpclient/methods/multipart/StringPart;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

    .line 118
    aput-object v4, v16, v11

    move v11, v12

    .end local v12           #i:I
    .restart local v11       #i:I
    goto :goto_2

    .line 122
    .end local v11           #i:I
    .end local v15           #param:Lcom/mime/qweibo/QParameter;
    .restart local v12       #i:I
    :cond_4
    :try_start_2
    invoke-interface/range {v17 .. v17}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v15

    check-cast v15, Lcom/mime/qweibo/QParameter;

    .line 123
    .restart local v15       #param:Lcom/mime/qweibo/QParameter;
    new-instance v6, Ljava/io/File;

    iget-object v3, v15, Lcom/mime/qweibo/QParameter;->mValue:Ljava/lang/String;

    invoke-direct {v6, v3}, Ljava/io/File;-><init>(Ljava/lang/String;)V
    :try_end_2
    .catch Ljava/io/FileNotFoundException; {:try_start_2 .. :try_end_2} :catch_1

    .line 124
    .local v6, file:Ljava/io/File;
    add-int/lit8 v11, v12, 0x1

    .end local v12           #i:I
    .restart local v11       #i:I
    :try_start_3
    new-instance v3, Lorg/apache/commons/httpclient/methods/multipart/FilePart;

    iget-object v4, v15, Lcom/mime/qweibo/QParameter;->mName:Ljava/lang/String;

    invoke-virtual {v6}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v5

    .line 125
    invoke-static {v6}, Lcom/mime/qweibo/utils/QHttpUtil;->getContentType(Ljava/io/File;)Ljava/lang/String;

    move-result-object v7

    const-string v8, "UTF-8"

    invoke-direct/range {v3 .. v8}, Lorg/apache/commons/httpclient/methods/multipart/FilePart;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;)V

    .line 124
    aput-object v3, v16, v12
    :try_end_3
    .catch Ljava/io/FileNotFoundException; {:try_start_3 .. :try_end_3} :catch_0

    move v12, v11

    .end local v11           #i:I
    .restart local v12       #i:I
    goto :goto_3

    .line 127
    .end local v6           #file:Ljava/io/File;
    .end local v12           #i:I
    .end local v15           #param:Lcom/mime/qweibo/QParameter;
    .restart local v11       #i:I
    :catch_0
    move-exception v9

    .line 128
    .local v9, e:Ljava/io/FileNotFoundException;
    :goto_4
    invoke-virtual {v9}, Ljava/io/FileNotFoundException;->printStackTrace()V

    .line 129
    const/4 v3, 0x0

    goto/16 :goto_0

    .line 127
    .end local v9           #e:Ljava/io/FileNotFoundException;
    .end local v11           #i:I
    .restart local v12       #i:I
    :catch_1
    move-exception v9

    move v11, v12

    .end local v12           #i:I
    .restart local v11       #i:I
    goto :goto_4
.end method
